package com.Isb.Golf.inputgolfscore.connectivity;

import com.Isb.Golf.inputgolfscore.Utility.NetworkUtility;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;

public class InputGolfScoreLegacyConnection {

	/** The wifi manager. */
	private WifiManager mWifiManager = null;

	/** The context. */
	private Context mContext = null;

	/** The is wifi enabled. */
	private boolean isWifiEnabled = false;

	/** The is wifi connected. */
	private boolean isConnected = false;

//    /** The connectivity listener. */
//    private XL1BConnectivityListener mConnectivityListener = null;


	public InputGolfScoreLegacyConnection(Context context){
		mContext = context;

		mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
		isWifiEnabled = false;
		isConnected = false;
	}

	public class WifiBroadcastReceiver extends BroadcastReceiver {
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if(WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)){
				setIsWifiEnabled(mWifiManager.isWifiEnabled());
			} else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
				setIsConnected(NetworkUtility.isConnected(mContext));
			} else if(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) {
			} else {
			}
		}
	}

	protected void setIsWifiEnabled(boolean isEnabled) {
		if (isWifiEnabled == isEnabled) {
			return;
		}

		// update the wifi state
		this.isWifiEnabled = isEnabled;

//		// notify about wifi state change to controller
//		if (mConnectivityListener != null) {
//			mConnectivityListener.onLegacyStateChange(isEnabled);
//		}
	}

	protected void setIsConnected(boolean connected) {
		if (isConnected == connected) {
			return;
		}

//		this.isWifiEnableNotified = false;
		// update the wifi connection state
		isConnected = connected;
//		mConnectivityListener.onLegacyConnectionChange(connected);
    }
}
